package com.ydd.controller.user;


import com.ydd.dto.*;
import com.ydd.entity.YddUser;
import com.ydd.result.Result;
import com.ydd.service.YddArticleService;
import com.ydd.service.YddUserDataService;
import com.ydd.service.YddUserService;
import io.swagger.annotations.Api;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@Api(tags = "用户相关")
@RequestMapping("/user")
public class MyArticleController {
    @Autowired
    private YddArticleService articleService;
    @Autowired
    private YddUserDataService dataService;
    @Autowired
    private YddUserService userService;

    /**
     * 查看我的文章
     *
     * @param dto
     * @return
     */
    @GetMapping("/myArticle")
    public Result myArticlePage(MyArticlePageDTO dto) {

        return articleService.myArticlePage(dto);

    }

    /**
     * 我的收藏/点赞
     *
     * @param dto
     * @return
     */
    @GetMapping("/userDataList")
    public Result userDataList(UserDataPageDTO dto) {

        return dataService.userDataList(dto);
    }

    /**
     * 根据id查看文章
     *
     * @param id
     * @return
     */
    @GetMapping("/rowInfo")
    public Result selectByArticleId(Long id) {

        return articleService.selectByArticleId(id);

    }

    /**
     * 修改文章
     *
     * @param dto
     * @return
     */
    @PostMapping("/editArticle")
    public Result editArticle(@RequestBody EditArticleDTO dto) {
        return articleService.editArticle(dto);

    }

    /**
     * 修改用户资料
     *
     * @return
     */
    @PostMapping("/update")
    public Result updateUser(@RequestBody UpdateUserDTO dto) {

        return userService.updateUser(dto);

    }

    /**
     * 点赞/取消点赞和收藏/取消收藏
     *
     * @return
     */
    @GetMapping("/userDataHandle")
    public Result userDataHandle(UserDataHandleDTO dto) {

        return articleService.userDataHandle(dto);

    }

    /**
     * 发布文章
     *
     * @return
     */
    @PostMapping("/addArticle")
    public Result addArticle(@RequestBody AddArticleDTO dto) {

        return articleService.addArticle(dto);

    }

    /**
     * 删除我的文章
     *
     * @return
     */
    @GetMapping("/delArticle")
    public Result delArticle(Long id) {
        return articleService.delArticle(id);
    }

    /**
     * 获取用户信息
     * @return
     */
    @GetMapping("/getUserInfo")
    public Result getUserInfo(){

        return  userService.getUserInfo();
    }

}
